package cn.mesmile.interview.demo;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author zb
 * @date 2021/11/11 16:06
 * @Description
 */
public class Demo2File {

    public static void main(String[] args) {
        int [] a = {1,2,3,4,5,6,7};
        int [] b = new int[10];
        System.arraycopy(a,0,b,0,3);
        List<Integer> integers = new ArrayList<>();
        for (int i : b) {
            boolean add = integers.add(i);
        }
        // b = [1, 2, 3, 0, 0, 0, 0, 0, 0, 0]
        System.out.println("b = " + integers);


        TreeMap<Integer, String> treeMap = new TreeMap<>(new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    // -1 升序 1 降序
                    if (o1 < o2) {
                        return 1;
                    }
                    if (o1 > o2) {
                        return -1;
                    }
                    return 0;
                }
        });
        treeMap.put(1,"测试1");
        treeMap.put(2,"测试1");
        treeMap.put(3,"测试1");
        treeMap.put(6,"测试1");
        treeMap.put(5,"测试1");
        treeMap.put(4,"测试1");

        System.out.println("treeMap = " + treeMap);


        File file = new File("D:\\inter");
        List<String> files = new ArrayList<>();
        getFiles(file, files);
        System.out.println("files.size() = " + files.size());
        files.forEach(path ->{
            System.out.println("path = " + path);
        });

        List<String> list = new ArrayList<>();
        for(int i=0; i<10; i++){
            list.add(""+i);
        }
        System.out.println(list.size());
        list.add("mesmile.cn");
        System.out.println(list.size());
    }

    public static void getFiles(File file,List<String> paths){
        File[] files = file.listFiles();
        if (files == null || files.length == 0){
            return;
        }
        for (File file1 : files) {
            if (file1.isFile()){
                paths.add(file1.getPath());
            }else {
                getFiles(file1, paths);
            }
        }
    }
}
